import 'package:flutter/material.dart';


/// 单元格
class Cell extends StatelessWidget {

  Widget leftItem;

  Widget rightItem;

  void Function()? onTab;

  void Function()? onLongPress;

  Decoration? decoration;

  EdgeInsets? padding;

  Cell({Key? key, required this.leftItem, required this.rightItem, this.onTab,this.onLongPress,this.decoration, this.padding}) : super(key: key);

  Cell.titleCell({
    super.key,
    required String title,
    TextStyle? titleStyle,
    Widget? rightItem,
    this.onTab,
    this.decoration,
    this.padding
  }):
        leftItem = Text(title, style: titleStyle,),
        rightItem=rightItem ?? const SizedBox()
  ;

  static Widget hitIconItem({Decoration? decoration, IconStyle? iconStyle, required IconData iconData, required String tips, TextStyle? tipsStyle, double gap=3}){
    return Row(
      children: [
        Text(tips, style: tipsStyle,),
        SizedBox(width: gap,),
        iconItem(iconData: iconData, iconStyle: iconStyle)
      ],
    );
  }

  static Widget iconItem({IconStyle? iconStyle, required IconData iconData}){
    return iconStyle==null?Icon(iconData):iconStyle.icon(iconData);
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onLongPress: onLongPress,
      onTap: onTab,
      child: DecoratedBox(
        decoration: decoration??const BoxDecoration(),
        child: Padding(
          padding: padding ?? const EdgeInsets.all(0.0),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              leftItem,
              rightItem,
            ],
          ),
        ),
      ),
    );
  }
}


class IconStyle {

  final double? size;
  final double? fill;
  final double? weight;
  final double? grade;
  final double? opticalSize;
  final Color? color;
  final List<Shadow>? shadows;
  final String? semanticLabel;
  final TextDirection? textDirection;

  IconStyle({
    this.size,
    this.fill,
    this.weight,
    this.grade,
    this.opticalSize,
    this.color,
    this.shadows,
    this.semanticLabel,
    this.textDirection
  });

  Icon icon(IconData iconData){
    return Icon(
      iconData,
      size: size,
      fill: fill,
      weight: weight,
      grade: grade,
      opticalSize: opticalSize,
      color: color,
      shadows: shadows,
      semanticLabel: semanticLabel,
      textDirection: textDirection,
    );
  }

}
